package servletlearn.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet(name = "Session1Servlet", urlPatterns = "/s1Servlet")
public class Session1Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Cookie cookie = new Cookie("JSESSIONID", session.getId());
        cookie.setPath("/ZY");
        cookie.setMaxAge(30 * 60);
        response.addCookie(cookie);
        session.setAttribute("name", "洗衣机");
    }
}
